﻿@model App.Models.SysSample
@using App.Common;
@using App.Models;

@{
    ViewBag.Title = "新增";
    Layout = "~/Views/Shared/Create.cshtml";
}

    @using (Html.BeginForm("Create", "Home", null, FormMethod.Post, new { Id = "CreateForm" }))
    {
        @Html.ValidationSummary(true)
        <table class="detail setTextWidth200">
            <tbody>
                <tr>
                    <td style="width: 100px; text-align: right;">
                        @Html.LabelFor(model => model.Id)：
                    </td>
                    <td>
                        @Html.EditorFor(model => model.Id)
                    </td>
                    <td>
                        @Html.ValidationMessageFor(model => model.Id)
                    </td>

                    <td style="width: 100px; text-align: right;">
                        @Html.LabelFor(model => model.Name)：
                    </td>
                    <td>
                        @Html.EditorFor(model => model.Name)
                    </td>
                    <td>
                        @Html.ValidationMessageFor(model => model.Name)
                    </td>
                </tr>
                <tr>
                    <td style="width: 100px; text-align: right;">
                        @Html.LabelFor(model => model.Age)：
                    </td>
                    <td>
                        @Html.EditorFor(model => model.Age)
                    </td>
                    <td>
                        @Html.ValidationMessageFor(model => model.Age)
                    </td>

                    <td style="width: 100px; text-align: right;">
                        @Html.LabelFor(model => model.Bir)：
                    </td>
                    <td>
                        @Html.TextBoxFor(model => model.Bir)
                    </td>
                    <td>
                        @Html.ValidationMessageFor(model => model.Bir)
                    </td>
                </tr>

                <tr>
                    <td style="width: 100px; text-align: right;">
                        @Html.LabelFor(model => model.Note)：
                    </td>
                    <td>
                        @Html.EditorFor(model => model.Note)
                    </td>
                    <td>
                        @Html.ValidationMessageFor(model => model.Note)
                    </td>

                    <td style="width: 100px; text-align: right;">
                        @Html.LabelFor(model => model.CreateTime)：
                    </td>
                    <td>
                        @Html.TextBoxFor(model => model.CreateTime)
                    </td>
                    <td>
                        @Html.ValidationMessageFor(model => model.CreateTime)
                    </td>
                </tr>
                <tr>
                    <td style="width: 100px; text-align: right;">
                        @Html.LabelFor(model => model.Photo)：
                    </td>
                    <td>
                        @Html.TextBoxFor(model => model.Photo)
                    </td>
                    <td>
                        @Html.ValidationMessageFor(model => model.Photo)
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    }

<script type="text/javascript">
    $(function () {
        $.extend(dialog.opgions, {
            onSave: Save
        });

        $("#EditForm").form({
            url: "Home/Create"
        });
    });

    function Save() {
        $('#CreateForm').form('submit', {
            success: function (data) {
                if (data) {
                    if (data.ret) {
                        $.messager.alert('温馨提示', '新增成功！', function () {
                            //跳转到Detail界面，待处理
                            console.log(data.data);
                        });
                    } else if (data.messager) {
                        $.messager.alert('温馨提示', data.messager);
                    }
                } else {
                    $.messager.alert('温馨提示', '新增失败！');
                }
            }
        });
    }
</script>
